﻿Imports System.Collections.Generic
Imports System.Data
Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL
Imports System.Xml

Public Class BuscarPuertos

    Inherits System.Web.UI.Page
    Dim itemgridview As GridViewRow
    Dim casilla As System.Web.UI.WebControls.CheckBox

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ListarPuerto()
        End If
    End Sub

    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        ListarPuerto()
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Write("<script language=Javascript>window.close();</script>")
    End Sub

    Private Sub ListarPuerto()

        Dim objPuertoBE As New PuertosBE
        Dim objUtil As New Funciones
        If txtNave.Text.Trim <> "" Then
            objPuertoBE.Descripcion = objUtil.ReemplazarTexto(txtNave.Text.Trim)
        Else
            objPuertoBE.Descripcion = ""
        End If

        Dim objPuerto As New PuertosBC
        dtgPuerto.DataSource = objPuerto.ListaPuertos(objPuertoBE)
        dtgPuerto.DataBind()
        If dtgPuerto.Rows.Count <= 0 Then
            dtgPuerto.Visible = False
            lblError.Visible = True
        Else
            dtgPuerto.Visible = True
            lblError.Visible = False
        End If
    End Sub


    Protected Sub btnSeleccionar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSeleccionar.Click
        Dim dt As New DataTable
        Dim sCodPuerto As String = String.Empty
        Dim sDesPuerto As String = String.Empty
        Dim scadena As String

        For Each Me.itemgridview In dtgPuerto.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")

            If casilla.Checked = True Then
                sCodPuerto = CType(itemgridview.FindControl("lblcodigo"), Label).Text
                sDesPuerto = CType(itemgridview.FindControl("lblDescripcion"), Label).Text
            End If

        Next
        scadena = sDesPuerto
        If sDesPuerto.ToString.Trim = "" Then
            Session("BPDesPuerto") = ""
            Session("BPCodPuerto") = ""
            Exit Sub
        End If
        '  Response.Write("<script language=Javascript>window.returnValue = " & scadena & ";</script>")
        Response.Write("<script language=Javascript>window.close();</script>")
        Session("BPCodPuerto") = sCodPuerto
        Session("BPDesPuerto") = sDesPuerto

    End Sub


    Sub Cambiarpagina(ByVal sender As Object, ByVal e As GridViewPageEventArgs)


        Dim objPuertoBE As New PuertosBE
        Dim objUtil As New Funciones
        If txtNave.Text.Trim <> "" Then
            objPuertoBE.Descripcion = objUtil.ReemplazarTexto(txtNave.Text.Trim)
        Else
            objPuertoBE.Descripcion = ""
        End If

        Dim objPuerto As New PuertosBC
        dtgPuerto.PageIndex = e.NewPageIndex
        dtgPuerto.DataSource = objPuerto.ListaPuertos(objPuertoBE)
        dtgPuerto.DataBind()
        If dtgPuerto.Rows.Count <= 0 Then
            dtgPuerto.Visible = False
            lblError.Visible = True
        Else
            dtgPuerto.Visible = True
            lblError.Visible = False
        End If


    End Sub

End Class